package com.qingcheng.dao;

import com.qingcheng.pojo.order.Order;
import com.qingcheng.vo.goods.OrderDetailsVo;
import com.qingcheng.vo.goods.OrderVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface OrderMapper extends Mapper<Order> {

    @Select("SELECT\n" +
            "\to.id id,\n" +
            "\to.username username,\n" +
            "\to.receiver_mobile receiverMobile,\n" +
            "\toi.NAME NAME,\n" +
            "\to.shipping_code CODE,\n" +
            "\to.consign_time consignMime,\n" +
            "\to.consign_status consignStatus\n" +
            "FROM\n" +
            "\ttb_order o,\n" +
            "\ttb_order_item oi \n" +
            "WHERE\n" +
            "\to.id = oi.order_id")
    List<OrderVo> selectAllDetermineOrder();

    @Select("SELECT o.order_status,count(*) num FROM tb_order o GROUP BY order_status")
    List<Map> selectCountStatus();

    @Select("SELECT\n" +
            "\to.*,\n" +
            "\ta.content content,\n" +
            "\ttake_timeout \n" +
            "FROM\n" +
            "\ttb_order o\n" +
            "\tLEFT JOIN qingcheng_business.tb_activity a ON o.activity_id = a.id\n" +
            "\tLEFT JOIN tb_order_config ON o.order_config_id = a.id \n" +
            "WHERE\n" +
            "\to.id = #{id}")
    OrderDetailsVo selectOrderById(String id);

    /**
     * 按照状态查询对应状态的订单总数
     * @param status
     * @return
     */
    @Select("SELECT COUNT(*) FROM tb_order WHERE order_status = #{status}")
    int findByStatus(@Param("status")int status);

    /**
     *
     * @param time
     * @return
     */
    @Select("SELECT COUNT(*) FROM tb_order WHERE TO_DAYS(create_time) = TO_DAYS(#{time})")
    int getSum(@Param("time") String time);

    @Select("SELECT SUM(pay_money) FROM tb_order WHERE TO_DAYS(create_time) = TO_DAYS(#{time})")
    String getpaysum(@Param("time")String time);
}
